package org.example.server.controller;

import org.example.api.response.BaseResponse;
import org.example.api.response.StatusCode;
import org.example.server.dto.BaseDto;
import org.example.server.server.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shkstart
 * @create 2020-03-24 19:52
 */
@RestController
@RequestMapping("base")
public class BaceController extends AbstractController {

    @Autowired
    BaseService baseService;
    @RequestMapping(value = "info",method = RequestMethod.GET)
    public BaseResponse info(){
        BaseResponse response=new BaseResponse(StatusCode.success);
        try {
            response.setDate("-------------响应数据-------------");
        }catch (Exception e) {
            response = new BaseResponse(StatusCode.fail.getCode(),e.getMessage());
        }
        return response;
    }
    @RequestMapping(value = "list",method = RequestMethod.GET)
    public BaseResponse list(){
        BaseResponse response=new BaseResponse(StatusCode.success);
        try {
            List<BaseDto> list = baseService.getList();
            log.info("打印出list日志信息{}",list);
            response.setDate(list);
        }catch (Exception e) {
            response = new BaseResponse(StatusCode.fail.getCode(),e.getMessage());
        }
        return response;
    }
}
